import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface FormulaDetailProp {
  id: number;
  account_id: number;
  business_id: number;
  formula_id: string;
  formula_version: string;
  version: string;
  formula_subid: string;
  name: string;
  icon: string;
  device_type: string;
  note: string;
  delete_status: number;
  publish_status: number;
  release_status: number;
  tag_list: string;
  is_effective: number | string;
  update_time: Date;
  create_time: Date;
  publish_time: Date;
}

export const getformulaDetailList = (data?: object) => {
  return http.request<ResultProps<FormulaDetailProp[]>>(
    "post",
    "/formula/getList",
    {
      data
    }
  );
};

export const formulaDelete = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formula/del", {
    data
  });
};

/* export const versionsAdd = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formulaVersion/add", {
    data
  });
};

export const versionsUpdate = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formulaVersion/upd", {
    data
  });
};

export const versionsDelete = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formulaVersion/del", {
    data
  });
};

export const updateStatus = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formulaVersion/publish", {
    data
  });
};
 */

export interface TagProp {
  id: number;
  account_id: number;
  business_id: number;
  name: string;
  icon: string;
  device_type: string;
  note: string;
  delete_status: number;
  update_time: Date;
  create_time: Date;
}

export const getTagList = (data?: object) => {
  return http.request<ResultProps<TagProp[]>>("post", "/tag/getList", {
    data
  });
};

export const tagAdd = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/tag/add", {
    data
  });
};

export const tagUpd = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/tag/upd", {
    data
  });
};

export const tagDel = (data?: object) => {
  return http.request<ResultProps<null>>("post", "/tag/del", {
    data
  });
};

export const formulaAdd = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/formula/add", {
    data
  });
};

export const formulaAddImport = (data?: object) => {
  return http.request<ResultProps<any[]>>(
    "post",
    "/formula/add",
    {
      data
    },
    {
      beforeResponseCallback: () => {}
    }
  );
};

export const formulaAddCheck = (data?: object) => {
  return http.requestJson<ResultProps<any[]>>("post", "/formula/addCheck", {
    data
  });
};

export const formulaUpd = (data?: object) => {
  return http.request<ResultProps<any[]>>("post", "/formula/upd", {
    data
  });
};

export interface FormulaDetailProp {
  id: number;
  account_id: number;
  business_id: number;
  formula_id: string;
  formula_version: string;
  version: string;
  formula_subid: string;
  name: string;
  icon: string;
  device_type: string;
  note: string;
  delete_status: number;
  publish_status: number;
  release_status: number;
  release_time: null;
  publish_time: Date;
  create_time: Date;
  update_time: Date;
  tag_list: string;
  third_value: null;
  material_list: MaterialList[];
  specification_list: SpecificationList[];
  formula_detail: FormulaDetail[];
  is_effect: null;
}

export interface FormulaDetail {
  edit_status: number;
  materialSpecs: MaterialSpec[];
  materialAmount: MaterialAmount[];
}

export interface MaterialAmount {
  amount: number;
  amount_unit: string;
  material_id: string;
  material_name: string;
}

export interface MaterialSpec {
  specification_id: number;
  attr: string;
}

export interface MaterialList {
  id: number;
  material_id: string;
  account_id: number;
  business_id: number;
  name: string;
  note: string;
  standard_amount: null;
  amount_unit: string;
  barcode: string;
  use_barcode: boolean;
  delete_status: number;
  publish_status: number;
  type_id: number;
  clean_time: number;
  overdue_time: number;
  cold_time: null;
  update_time: Date;
  create_time: Date;
  spec: null;
  material_config: string;
  type_name: string;
  index: number;
}

export interface SpecificationList {
  id: number;
  formula_subid: string;
  specification_id: number;
  specification_name: string;
  specification_attr: string;
  check_attr: string;
  create_time: Date;
}

export const formulaGetDetail = (data?: object) => {
  return http.request<ResultProps<FormulaDetailProp>>(
    "get",
    "/formula/getDetail",
    {
      params: data
    }
  );
};

export const formulaGetDetailList = (data?: object) => {
  return http.request<ResultProps<FormulaDetailProp[]>>(
    "post",
    "/formula/getDetailList",
    {
      params: data
    }
  );
};

export interface ThirdRelationListProp {
  id: number;
  account_id: number;
  business_id: number;
  third_value: string;
  autata_value: string;
  autata_version: number;
  autata_content_key: string;
  is_effective: number | string;
  update_time: Date;
  create_time: Date;
}

export const thirdRelationGetListAll = (data?: object) => {
  return http.requestJson<ResultProps<ThirdRelationListProp[]>>(
    "post",
    "/thirdRelation/getListAll",
    {
      data
    }
  );
};
